package com.devmindset.legoframework.usage.client.component;

import com.devmindset.legoframework.client.mvc.LegoComponent;
import com.devmindset.legoframework.client.mvc.LegoModel;
import com.devmindset.legoframework.client.mvc.metadata.ComponentStory;
import com.devmindset.legoframework.client.mvc.metadata.Stories;
import com.devmindset.legoframework.usage.client.NativeService;
import com.devmindset.legoframework.usage.client.constants.UsageConstants;
import com.devmindset.legoframework.usage.client.event.Events;
import com.devmindset.legoframework.usage.client.text.UsageTexts;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.ImgButton;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;

/**
 * Header Component.
 * 
 * @author <a href="ice.penov@devmindset.com">Ice Penov</a>
 */
public class HeaderComponent extends LegoComponent {
		
	/** {@inheritDoc} */
	@Override
	public Canvas construct(LegoModel model) {		
		final ImgButton en = new ImgButton();
		en.setSrc("lang_en.jpg");
		en.setHeight(14);
		en.setWidth(23);
		en.setBorder(UsageConstants.COMPONENT_BORDER);
		en.setTooltip(UsageTexts.get().switchToEnglish());
		en.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				NativeService.toEnglishEventHandler();				
			}
		});
		
		final ImgButton de = new ImgButton();
		de.setSrc("lang_de.jpg");
		de.setHeight(14);
		de.setWidth(23);
		de.setBorder(UsageConstants.COMPONENT_BORDER);
		de.setTooltip(UsageTexts.get().switchToGerman());
		de.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				NativeService.toGermanEventHandler();
			}
		});
		
		HLayout layout = new HLayout();
		layout.setWidth100();
		layout.setHeight100();
		layout.setAlign(Alignment.RIGHT);
		layout.setMembersMargin(4);
		Label l = new Label("<b>" + UsageTexts.get().language() + " : </b>");
		l.setWrap(false);
		l.setHeight(12);
		l.setWidth(30);
		layout.addMember(l);
		layout.addMember(en);
		layout.addMember(de);
		layout.setPadding(3);
		
		return layout;
	}
		
	/** {@inheritDoc} */
	@Override
	public void calculate(LegoModel model) {
		//nothing to additionally calculate for this component.
	}
	
	/** {@inheritDoc} */
	public ComponentStory myStory() {
		return Stories.component()
			.constructedBy(Events.RENDER_HEADER_COMPONENT)
			.knownAs("Header Component");
	}

}